package com.wanye.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Created by wanye on 2017/9/18.
 */
public class PhoneConstraint implements ConstraintValidator<Phone,String> {
    private String regexp;


    @Override
    public void initialize(Phone constraintAnnotation) {
        this.regexp = constraintAnnotation.regexp();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null) {
            return true;
        }

        if (value.matches(regexp)) {
            return true;
        }
        return false;
    }
}
